'use strict';

const Controller = require('egg').Controller;
const { getCookieValue } = require('../public/processCookies');
/**
* @controller OltTypeController 注释必写，swagger-doc是根据这段注释来生成接口的 ）。
*/
class OltTypeController extends Controller {

  async list() {
    /**
        * @summary olttype。
        * @description olttype。
        * @router get /olttypelist
        * @request query integer limit
        * @request query integer page
        */
    const params = this.ctx.query;
    const { id: tid } = getCookieValue(this.ctx.cookies, 'token', 'tenant');
    params.tid = tid;
    const result = await this.ctx.service.oltType.list(params);
    this.ctx.body = {
      msg: '',
      status: 200,
      data: result.rows,
      count: result.count,
    };
  }
  async delete() {
    /**
        * @summary olttype。
        * @description olttype。
        * @router get /olttypedelete
        * @request query String id
        */
    const params = this.ctx.query;
    await this.ctx.service.oltType.delete(params);
    this.ctx.body = {
      msg: 'delete successful',
      status: 200,
    };
  }
  async listAll() {
    /**
        * @summary olttypelistall
        * @description olttypelistall
        * @router get /olttypelistall
        */
    const { id: tid } = getCookieValue(this.ctx.cookies, 'token', 'tenant');
    const result = await this.ctx.service.oltType.listAll(tid);
    this.ctx.body = {
      data: result,
    };
  }
  async scriptList() {
    /**
        * @summary scriptlist
        * @description scriptlist
        * @router get /scriptlist
        * @request query integer limit
        * @request query integer page
        * @request query string id
        */
    const params = this.ctx.query;
    const result = await this.ctx.service.oltType.scriptList(params);
    this.ctx.body = {
      msg: '',
      status: 200,
      data: result.rows,
      count: result.count,
    };
  }
  async scriptEdit() {
    /**
        * @summary scriptedit
        * @description scriptedit
        * @router post /scriptedit
        * @request body scriptedit value 传入参数
        */
    const params = this.ctx.request.body;
    const result = await this.ctx.service.oltType.scriptEdit(params);
    this.ctx.body = {
      msg: result.msg,
    };
  }
}
module.exports = OltTypeController;
